package com.dlc.felear.xiaoensale.utils;

import android.os.Handler;
import android.os.Message;
import android.util.Log;

import com.dlc.felear.xiaoensale.constant.Constant;
import com.dlc.felear.xiaoensale.factory.CmdList;

import org.simple.eventbus.EventBus;

public class TestHelper implements Handler.Callback {
    private static final String TAG="TestHelper";
    private Handler handler;

    public TestHelper(){
        handler=new Handler(this);
    }

    @Override
    public boolean handleMessage(Message msg) {
        return false;
    }

    public void recieveCmd(byte[] data){
        log("指令:"+HexUtil.bytes2HexString(data));
        if(CmdList.checkDataComplete(data)&&data[0]==(byte)0xA5){
            if(data[2]==1){
                //表示开关量的动作
                sendInfo(data[1],2);
            }
            switch (data[1]){
                case (byte) 0x10:
                    log("锅加热");
                    break;
                case (byte) 0x11:
                    log("锅旋转");
                    break;
                case (byte) 0x12:
                    log("洗锅");
                    break;
                case (byte) 0x13:
                    log("出锅");
                    break;
                case (byte) 0x14:
                    log("加食材");
                    break;
                case (byte) 0x15:
                    log("锅盖");
                    break;
                case (byte) 0x16:
                    log("固体调料");
                    break;
                case (byte) 0x17:
                    log("液体调料");
                    break;
                case (byte) 0x18:
                    log("抽风机");
                    break;
                case (byte) 0x19:
                    log("复位");
                    break;
            }
        }else {
            log("数据校验失败");
        }
    }


    private void sendInfo(int cmd,int result){
        EventBus.getDefault().post(CmdList.result(cmd,result), Constant.ACTION_CMD_INFO_RESULT);
    }

    private void log(String msg){
        Log.e(TAG,msg);
    }
}
